package com.ztgf.logistics.api.client;

import com.baidu.aip.nlp.AipNlp;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.logistics.models.service.ILogisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * author: chenyu.wang
 * date: 2020-05-23 11:36
 * Description:
 */
@RestController
@RequestMapping(value = "/api/logistics")
@Api(value = "LogisticsApiController", tags = "物流信息接口")
@Slf4j
public class LogisticsApiController {


    @DubboReference
    private ILogisticsService logisticsService;

    @PostMapping(value = "/queryLogistics")
    @ApiOperation(value = "查询订单物流信息", notes = "查询订单物流信息")
    public Result<?> queryLogistics(Long id) {
        if (id == null) {
            new Result<>(CodeEnum.FAIL_100002);
        }
        List<Object> result = logisticsService.queryLogistics(id);
        return new Result<>(result);
    }

    @PostMapping(value = "/queryLogisticsByWx")
    @ApiOperation(value = "根据运单号查询订单物流信息", notes = "根据运单号查询订单物流信息")
    public Result<?> queryLogisticsByWx(String mailNo) {
        if (mailNo == null) {
            new Result<>(CodeEnum.FAIL_100002);
        }
        List<Object> result = logisticsService.queryLogisticsByWx(mailNo);
        return new Result<>(result);
    }

    @PostMapping(value = "/queryDepponList")
    @ApiOperation(value = "根据运单号查询德邦轨迹", notes = "根据运单号查询德邦轨迹")
    public Result<?> queryDepponList(String mailNo) {
        return new Result<>(logisticsService.queryDepponList(mailNo));
    }

    @PostMapping(value = "/queryAfterLogistics")
    @ApiOperation(value = "售后订单物流信息", notes = "售后订单物流信息")
    public Result<?> queryAfterLogistics(Long id) {
        if (id == null) {
            new Result<>(CodeEnum.FAIL_100002);
        }
        List<Object> result = logisticsService.queryAfterLogistics(id);
        return new Result<>(result);
    }

    @PostMapping(value = "/queryRecentLogistics")
    @ApiOperation(value = "获取订单最新一条物流记录", notes = "获取订单最新一条物流记录")
    public Result<?> queryRecentLogistics(Long orderId) {
        if (orderId == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            List<Object> list = logisticsService.queryRecentLogistics(orderId);
            return new Result<>(list);
        }
    }

    @PostMapping(value = "/queryAfterRecentLogistics")
    @ApiOperation(value = "获取售后订单最后一条物流信息", notes = "获取售后订单最后一条物流信息")
    public Result<?> queryAfterRecentLogistics(Long orderId) {
        if (orderId == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            List<Object> list = logisticsService.queryAfterRecentLogistics(orderId);
            return new Result<>(list);
        }
    }

    @PostMapping(value = "/queryOrderInvoiceLogisticsInformation")
    @ApiOperation(value = "查询订单发票物流信息", notes = "查询订单发票物流信息")
    public Result<?> queryOrderInvoiceLogisticsInformation(Long orderInvoiceId) {
        if (orderInvoiceId == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        Result<?> result = logisticsService.queryOrderInvoiceLogisticsInformation(orderInvoiceId);
        return new Result<>(result);
    }

    @PostMapping(value = "/querySysInvoiceLogisticsInformation")
    @ApiOperation(value = "查询平台开票发票物流信息", notes = "查询平台开票发票物流信息")
    public Result<?> querySysInvoiceLogisticsInformation(Long SysInvoiceId) {
        if (SysInvoiceId == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        Result<?> result = logisticsService.querySysInvoiceLogisticsInformation(SysInvoiceId);
        return new Result<>(result);
    }
//
@PostMapping(value = "/addressProcessing")
@ApiOperation(value = "地址处理解析根据百度云", notes = "地址处理解析根据百度云")
public Result<?> addressProcessing(String address) {
    if (address == null) {
        return new Result<>(CodeEnum.FAIL_100002);
    }
    Result<?> result = logisticsService.addressProcessing(address);
    return new Result<>(result);
}
}
